package cn.smbms.controller;

import cn.smbms.pojo.User;
import org.apache.log4j.Logger;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

import java.util.Map;

@Controller
public class IndexController{


    private Logger logger = Logger.getLogger(IndexController.class);
    @RequestMapping(value = "/hello")
    public String hello(@RequestParam(value = "userName",required = false)String userName, Model model){
        logger.info("index,"+userName);
        model.addAttribute("userName",userName);
        model.addAttribute(userName);
        model.addAttribute(11);
        User user = new User();
        user.setUserName(userName);
        model.addAttribute("currentUser",user);
        model.addAttribute(user);
        return "hello";
    }

    @RequestMapping(value = "/index")
    public ModelAndView index(@RequestParam(value = "userName",required = false)String userName){
        logger.info("index,"+userName);
        ModelAndView mv = new ModelAndView();
        mv.addObject("userName",userName);
        mv.setViewName("index");
        return mv;
    }


    @RequestMapping(value = "/hello2")
    public String hello2(@RequestParam(value = "userName",required = false)String userName, Map<String,Object> model){
        logger.info("hello,"+userName);

       model.put("userName",userName);
        return "hello";
    }

    @RequestMapping(value = "/success")
    public String success(@RequestParam(value = "useCode",required = false)String useCode, Model model){
        logger.info("useCode,"+useCode);
        model.addAttribute("useCode",useCode);

        return "success";
    }
}
